package org.csu.mypetstore.web.servlets.order;

import org.csu.mypetstore.domain.Order;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class ShippingAddressServlet extends HttpServlet {
    private static final String CONFIRM_ORDER="/WEB-INF/jsp/order/ConfirmOrder.jsp";

    private Order order;
    private String firstNAme;
    private String lastName;
    private String address1;
    private String address2;
    private String city;
    private String state;
    private String zip;
    private String country;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        firstNAme= req.getParameter("shipToFirstName");
        lastName= req.getParameter("shipToLastName");
        address1= req.getParameter("shipAddress1");
        address2= req.getParameter("shipAddress2");
        city= req.getParameter("shipCity");
        state= req.getParameter("shipState");
        zip= req.getParameter("shipZip");
        country= req.getParameter("shipCountry");

        HttpSession session= req.getSession();
        order=(Order) session.getAttribute("order");

        order.setShipToFirstName(firstNAme);
        order.setShipToLastName(lastName);
        order.setShipAddress1(address1);
        order.setShipAddress2(address2);
        order.setShipCity(city);
        order.setShipState(state);
        order.setShipZip(zip);
        order.setShipCountry(country);

        session.setAttribute("order", order);

        req.getRequestDispatcher(CONFIRM_ORDER).forward(req, resp);
    }
}
